package com.qq.BFMRSE.BF_MRSEController;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.qq.BFMRSE.BussinessService.userBusSerImpl;

@Controller
public class handlerLogin {
	@RequestMapping(value= "/login",method=RequestMethod.POST)
	public void handler(HttpServletRequest request,HttpServletResponse response){
		WebApplicationContext wac=WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());
		userBusSerImpl ubIm=(userBusSerImpl) wac.getBean("usBuIm");
		Logger log=Logger.getLogger(handlerLogin.class);
		String userName=request.getParameter("userName");
		String pwd=request.getParameter("pwd");
		System.out.println(userName+":"+pwd);
		boolean isTrue=ubIm.isLogin(userName, pwd);
		if(isTrue){
			log.info("User:"+userName+" login BF_MRSEServer.");
		}
		try {
			response.setCharacterEncoding("utf-8");
			response.setContentType("text/html;charset=utf-8");
			PrintWriter out=response.getWriter();
			out.println(isTrue);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
